import { createSelector, createSlice } from '@reduxjs/toolkit'
// import { getToList } from '@/store/slice/todoSlice'
const initialState = {
  value: 0,
  title: 'redux toolkit pre'
}
// 创建一个slice
export const counterSlice = createSlice({
  name: 'counter',
  initialState,
  // 定义reducers并生成关联操作
  reducers: {
    // 定义一个加的方法
    increment: (state) => {
      state.value += 1
    },
    increment2: (state, { payload }) => {
      state.value = state.value + payload.value
    },
    // 定义一个减的方法
    decrement: (state) => {
      state.value -= 1
    }
  }
})
// 导出加减的方法
export const { increment, decrement, increment2 } = counterSlice.actions
// console.log("counterSlice.actions;", counterSlice.actions);
// 默认导出
export default counterSlice.reducer

// function getValue(state) {
//   // console.log('list2', state.counter.value)
//   return state.counter.value
// }

// function getToList2(state) {
//   // console.log('list2', state.counter.value)
//   return state.todo
// }

function getTotal(list1, value) {
  // console.log('list1', list1, value)
  return list1.length + value
}
export const myNum = createSelector(
  [(state) => state.todo, (state) => state.counter.value],
  getTotal
)
// export const myNum = createSelector([getToList2, getValue], getTotal)
// export const myNum = createSelector([getToList, getValue], getTotal)
